module sw.modelist;
import sw.forwardmode, sw.admin.adminmodelist, sw.backup.backupmodelist, sw.google.googlemodelist, sw.unsupportedmode, sw.mode, sw.siteconfig, sw.global.globalmodelist;
version(Wiki)import sw.wiki.wikimodelist;
version(Upload)import sw.upload.uploadmodelist;
version(BugTracking)import sw.bugtracking.bugtrackingmodelist;

///モードファクトリのインターフェース
interface ModeFactory{
  ///prefixを返す
  static string prefix();
  ///モードを返す
  IMode getMode(string name);
}

template TModeFactory(){
  SiteConfig* cfg;
  this(SiteConfig* cfg){
    this.cfg = cfg;
  }
}

enum Type{
  Wiki=1,
  Uploader=2,
  BugTracking=4,
}
version(Wiki){
  const Type top=Type.Wiki;
}else version(Upload){
  version(BugTracking)static assert(0,"This combination is not supported.");
  const Type top=Type.Uploader;
}else version(BugTracking){
  const Type top=Type.BugTracking;
}else{
  static assert(0,"Please set version option");
}

///prefixからモードリストを取得
class ModeFactoryFactory{
  ///モードのリストを返す
  static ModeFactory getModeFactory(SiteConfig* cfg,string prefix){
    if(cfg.synchronizeURI!=""){
      switch(prefix){
        version(BugTracking){
          static if(top==Type.BugTracking){case "":}
          case BugTrackingModeFactory.prefix:
            return new ForwardModeFactory(cfg);
        }
        default:
      }
    }
    switch(prefix){
      version(Upload){
        static if(top==Type.Uploader){case "":}
        case UploadModeFactory.prefix:
          return new UploadModeFactory(cfg);
      }
      version(BugTracking){
        static if(top==Type.BugTracking){case "":}
        case BugTrackingModeFactory.prefix:
          return new BugTrackingModeFactory(cfg);
      }
      version(Wiki){
        case GoogleModeFactory.prefix:
          return new GoogleModeFactory(cfg);
        static if(top==Type.Wiki){case "":}
        case WikiModeFactory.prefix:
          return new WikiModeFactory(cfg);
      }
      case GlobalModeFactory.prefix:
        return new GlobalModeFactory(cfg);
      case BackupModeFactory.prefix:
        return new BackupModeFactory(cfg);
      case AdminModeFactory.prefix:
        return new AdminModeFactory(cfg);
      default:
    }
    return new UnsupportModeFactory(cfg);
  }
}
